package org.example.dao.goods;

import org.apache.ibatis.annotations.*;
import org.example.entity.Goods;
import org.example.entity.Specs;

import java.util.List;

@Mapper
public interface GoodsMapper {
    @Options(keyProperty = "goodsId",useGeneratedKeys = true)
    @Insert("insert into goods(goods_name, category_name, goods_image, goods_desc, status,order_id,goods_unit)" +
            "values (#{goodsName},#{categoryName},#{goodsImage},#{goodsDesc},#{status},#{orderId},#{goodsUnit})")
    boolean addGoods(Goods goods);

    List<Goods> listByReason(String goodsName,String categoryName,String status);

    @Insert("insert into specs(goods_id, specs_name, goods_price, order_id) " +
            "VALUES (#{goodsId},#{specsName},#{goodsPrice},#{orderId})")
    void addSpecs(Specs specs);

    @Select("select * from specs where goods_id = #{goodsId}")
    List<Specs> specsList(Integer goodsId);

    @Delete("delete from goods where goods_id=#{goodsId}")
    void deleteGoods(Integer goodsId);

    @Delete("delete from specs where goods_id=#{goodsId}")
    void deleteSpecs(Integer goodsId);

    @Update("update goods set goods_name =#{goodsName},category_name=#{categoryName},goods_image=#{goodsImage}," +
            "goods_desc=#{goodsDesc},goods_unit=#{goodsUnit},status=#{status},order_id=#{orderId}" +
            " where goods_id=#{goodsId}")
    void updateGoods(Goods goods);

    @Update("update specs set specs_name =#{specsName},goods_price=#{goodsPrice},order_id=#{orderId}" +
            " where specs_id=#{specsId}")
    void updateSpecs(Specs specs);

    @Select("select goods.goods_name from goods")
    List<String> list();

    @Select("select * from goods order by status desc ,order_id asc ")
    List<Goods> goodsList();

    @Select("select * from goods where goods.status='1'")
    List<Goods> getHot();

    @Select("select * from goods where category_name = #{categoryName}")
    List<Goods> getGoodsByCategory(String categoryName);

    @Select("select goods.goods_name from goods where goods_id = #{goodsId}")
    String getGoodsNameById(Integer goodsId);
}
